using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using System.Reflection;

public static class AsyncUtil 
{
    static HashSet<MethodInfo> runningKeyHash = new HashSet<MethodInfo>();
    public static async void TryStartSingle(Func<Task> asyncFunction)
    {
        var type = asyncFunction.Method.DeclaringType;
        var methodInfo = asyncFunction.Method;
        if(runningKeyHash.Contains(methodInfo))
        {
            return;
        }
        runningKeyHash.Add(methodInfo);
        try
        {
            await asyncFunction.Invoke();
        }
        finally
        {
            runningKeyHash.Remove(methodInfo);
        }
    }
}
